const t = require('@babel/types')
module.exports = () => {
  return {
    visitor:{
      CallExpression(path){
        if( path.node.callee.name === 'jsonParse'){
          let bodyParent = path.findParent((path)=>path.node.body)

          // var _jsonParse = require('./helpers/parser.js')
          const requireCallExpression = t.callExpression(t.identifier("require"),[t.stringLiteral('./plugin/helpers/parser.js')])
          const declartor = t.variableDeclarator(t.identifier('_jsonParse'), requireCallExpression)
          const declaration = t.variableDeclaration('var', [declartor])
          bodyParent.unshiftContainer('body',declaration)
          
          path.node.callee.name = '_jsonParse'
        }
      
      }
    }
  }
}